<%@page contentType="text/xml;charset=UTF-8" %><?xml version="1.0" encoding="utf-8"?>
<%@ page import="java.util.Map"
%><%@ page import="java.util.TreeMap"
%><%@ page import="java.util.List"
%><%@ page import="org.apache.commons.lang.StringEscapeUtils"
%><%@ page import="org.apache.taglibs.standard.tag.common.sql.ResultImpl"
%><%@ page import="javax.servlet.jsp.JspWriter"
%><%@ page import="java.io.IOException"
%><%@ page import="java.io.FileWriter"
%><%@ page import="java.io.BufferedWriter"
%><%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"
%><%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"
%><%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql"
%><%!
TreeMap<String,String[]> meta;
TreeMap<String,String[]> langs;

BufferedWriter log = null;

int currHandle = 0;
int submitter = 0;

void initLog () {
	try {
		FileWriter logFile = new FileWriter("d:/data/dspace/elis/convelisuser.log");
		log = new BufferedWriter(logFile);
	} catch(IOException e) {
	}
}

void exportOne(JspWriter out, String field, String tag) throws IOException {
	if (tag==null)tag=field;
	String[] value = meta.get(field);
	if (value != null && value.length > 0) {
		out.print('<');
		out.print(tag);
		out.print('>');
		out.print(StringEscapeUtils.escapeXml(value[0]));
		out.print("</");
		out.print(tag);
		out.print('>');
		for (int i = 1; i<value.length; i++) {
			log.write(""+currHandle);
			log.write(':');
			log.write(field);
			log.write('[');
			log.write(""+i);
			log.write("]=");
			log.write(value[i]);
			log.write("\r\n");
		}
	}
}

%><sql:setDataSource driver="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/dspace-elis" user="dspace-elis" password="dspace-elis"
/><sql:query var="handles">SELECT * FROM eperson ORDER BY eperson_id;
</sql:query><users xmlns="http://eprints.org/ep2/data/2.0">
<%
	initLog();
    ResultImpl handles = (org.apache.taglibs.standard.tag.common.sql.ResultImpl) pageContext.getAttribute("handles");
    log.write(""+handles.getRowCount()+" records to be exported...\r\n");
	for (Map<String,Object> row : handles.getRows()) {
		currHandle = (Integer)row.get("eperson_id");
		String currID = (String)row.get("netid");
		if (currID == null || currID.isEmpty()) {
			currID = (String)row.get("lastname") +'_'+ (String)row.get("firstname");
		}
%><user id="http://elistest.da.ulcc.ac.uk/id/user/<%=currHandle%>" xmlns="http://eprints.org/ep2/data/2.0">
<userid><%=currHandle%></userid>
<rev_number>1</rev_number>
<username><%=currID%></username>
<usertype><%=(String)row.get("user_type")%></usertype>
<joined>2002-09-19</joined>
<email><%=StringEscapeUtils.escapeXml((String)row.get("email"))%></email>
<frequency><%=(String)row.get("sub_frequency")%></frequency>
<mailempty>FALSE</mailempty>
<items_fields>
<item>lastmod</item><item>title</item><item>type</item><item>eprint_status</item>
</items_fields>
<review_fields><item>status_changed</item><item>title</item><item>type</item><item>userid</item>
</review_fields>
<name>
<family><%=StringEscapeUtils.escapeXml((String)row.get("lastname"))%></family>
<given><%=StringEscapeUtils.escapeXml((String)row.get("firstname"))%></given>
</name>
<dept><%=StringEscapeUtils.escapeXml((String)row.get("eprints_dept"))%></dept>
<org><%=StringEscapeUtils.escapeXml((String)row.get("eprints_org"))%></org>
<address><%=StringEscapeUtils.escapeXml((String)row.get("eprints_address"))%></address>
<hideemail><%=StringEscapeUtils.escapeXml((String)row.get("eprints_hieemail"))%></hideemail>
<onlinemail><%=StringEscapeUtils.escapeXml((String)row.get("eprints_onlinemail"))%></onlinemail>
<os><%=StringEscapeUtils.escapeXml((String)row.get("eprints_os"))%></os>
<saved_searches/>
</user><%
	}
	log.close();
%>
</users>

